package com.lizhaoshan.controller;

import com.lizhaoshan.common.Result;
import com.lizhaoshan.dao.OrdersDao;
import com.lizhaoshan.dto.OrdersDto;
import com.lizhaoshan.pojo.PageBean;
import com.lizhaoshan.service.OrdersService;
import com.lizhaoshan.vo.OrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @program: reggie
 * @description:
 * @author: lamour
 * @create: 2022-05-14 19:54
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @PutMapping
    public Result updateOrders(@RequestBody OrdersDto ordersDto){
        log.info("********修改订单******begin");
        boolean updateOrder = ordersService.updateOrder(ordersDto);
        log.info("********修改订单******end");
        return updateOrder?Result.success("修改订单成功") : Result.error("修改订单失败");
    }

    @GetMapping("/page")
    public Result getPagesOrders(@RequestParam(value = "beginTime", required = false) String beginTime,
                                 @RequestParam(value = "endTime", required = false) String endTime,
                                 @RequestParam(value = "number", required = false )String number,
                                 @RequestParam(value = "page", defaultValue = "1")Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        log.info("**********订单分页查询，begin");
        PageBean<OrderVo> getPagesOrders = ordersService.getPagesOrders(pageSize, page, number, beginTime, endTime);
        log.info("**********订单分页查询，end");

        return Objects.nonNull(getPagesOrders) ? Result.success(getPagesOrders) : Result.error("订单分页查询失败");
    }

}
